<?php

/**
 * XHTML_Tr_Element, xhtml_lib
 * 
 * This file contains the source code for the XHTML_Tr_Element class.
 * @author Fernando Jimenez Mocobono <fjmcool@gmail.com>
 * @version 0.1
 * @package xhtml_lib
 */

include_once "XHTML_Table_Common_Element.php";
include_once "XHTML_Flow.php";

/**
 * The XHTML_Tr_Element class is a handler for the tr xhtml-strict tag common 
 * inner elements as a part of a xhtml-strict php-handler implementation.
 */
abstract class XHTML_Tr_Element extends XHTML_Table_Common_Element {
    
     /**
     * Specifies an abbreviated version of the content in a cell.
     * 
     * @var string
     */
    protected $abbr;
    
    /**
     * Defines a name for this cell. (category_name).
     *
     * @var string
     */
    protected $axis;
    
    /**
     * A space-separated list of cell IDs that supply header information for 
     * the cell. This attribute allows text-only browsers to render the header 
     * information for a given cell.
     *
     * @var string
     */
    protected $headers;
    
    /**
     * Specifies if this cell provides header information for the rest of the 
     * row that contains it (row), or for the rest of the column (col), or 
     * for the rest of the row group that contains it (rowgroup), or for the 
     * rest of the column group that contains it.
     * Valid values: row, col, rowgroup, colgroup.
     *
     * @var string
     */
    protected $scope;
    
    /**
     * Indicates the number of rows this cell should span.
     *
     * @var integer
     */
    protected $rowSpan;
    
    /**
     * Indicates the number of columns this cell should span.
     *
     * @var integer
     */
    protected $colSpan;
    
    //inner elements
    
    /**
     * Array of XHTML_Flow inner elemens of this object.
     * 
     * @var array
     */
    protected $elements;
    
    
    // Methods
    
    /**
     * Constructs a XHTML_Tr_Element object.
     */
    function __construct()
    {
    	settype($this->elements, "array");
    }
    
    /**
     * Sets an abbreviated version of the content in a cell.
     *
     * @param string $abbr
     */
    function setAbbr($abbr)
    {
    	$this->abbr = $abbr;
    }
    
    /**
     * Gets an abbreviated version of the content in a cell.
     * 
     * @return string
     */
    function getAbbr()
    {
    	return $this->abbr;
    }
    
    /**
     * Sets a name for this cell. (category_name).
     *
     * @param string $axis
     */
    function setAxis($axis)
    {
    	$this->axis = $axis;
    }
    
    /**
     * Gets this cell's name. (category_name).
     *
     * @return unknown
     */
    function getAxis()
    {
    	return $this->axis;
    }
    
    /**
     * Sets a space-separated list of cell IDs that supply header information 
     * for the cell. This attribute allows text-only browsers to render the 
     * header information for this cell.
     *
     * @param string $headers
     */
    function setHeaders($headers)
    {
    	$this->headers = $headers;
    }
    
    /**
     * Gets a space-separated list of cell IDs (if set previously) that supply 
     * header information for the cell. This attribute allows text-only 
     * browsers to render the header information for this cell.
     *
     * @return string
     */
    function getHeaders()
    {
    	return $this->headers;
    }
    
    /**
     * Specifies if this cell provides header information for the rest of the 
     * row that contains it (row), or for the rest of the column (col), or 
     * for the rest of the row group that contains it (rowgroup), or for the 
     * rest of the column group that contains it.
     * Valid values: row, col, rowgroup, colgroup.
     *
     * @param string $scope
     */
    function setScope($scope)
    {
    	$this->scope = $scope;
    }
    
    /**
     * Specifies if this cell provides header information for the rest of the 
     * row that contains it (row), or for the rest of the column (col), or 
     * for the rest of the row group that contains it (rowgroup), or for the 
     * rest of the column group that contains it.
     * Valid values: row, col, rowgroup, colgroup.
     * 
     * @return string
     */
    function getScope()
    {
    	return $this->scope;
    }
    
    /**
     * Sets the number of rows this cell should span.
     *
     * @param integer $rowSpan
     */
    function setRowSpan($rowSpan)
    {
    	$this->rowSpan = $rowSpan;
    }
    
    /**
     * Gets the number of rows this cell should span.
     *
     * @return integer
     */
    function getRowSpan()
    {
    	return $this->rowSpan;
    }
    
    /**
     * Sets the number of columns this cell should span.
     *
     * @param integer $rowSpan
     */
    function setColSpan($colSpan)
    {
    	$this->colSpan = $colSpan;
    }
    
    /**
     * Gets the number of columns this cell should span.
     *
     * @return integer
     */
    function getColSpan()
    {
    	return $this->colSpan;
    }
    
    /**
     * Sets the XHTML_Flow elements array.
     *
     * @param array
     */
    function setElements($elements) {
        $this->elements = $elements;
    }
    
    /**
     * Gets the XHTML_Flow elements array.
     *
     * @return array
     */
    function getElements()
    {
        return $this->elements;
    }
    
    /**
     * Adds a XHTML_Flow element to the inner array of this object.
     * 
     * @param XHTML_Flow
     */
    function addElement(XHTML_Flow $element)
    {
        array_push($this->elements, $element);
    }
    
    /**
     * Removes a XHTML_Flow element from the inner array of this object.
     * 
     * @param XHTML_Flow
     */
    function removeElement(XHTML_Flow $element)
	{
        if (($res = array_search($element, $this->elements)) !== false) {
            unset($this->elements[$res]);
        }
    }
 
    // Overriding the toString method for a proper implementation.
    
    /**
    * Returns the string representation for echoing the class atributes.
    *
    * @return string
    */
    function toString()
    {
    	$auxString = parent::toString();
    	
    	if (isset($this->abbr)) {
    		$auxString = $auxString."abbr=\"".$this->abbr."\" ";
    	}
    	
    	if (isset($this->axis)) {
    		$auxString = $auxString."axis=\"".$this->axis."\" ";
    	}
    	
    	if (isset($this->headers)) {
    		$auxString = $auxString."headers=\"".$this->headers."\" ";
    	}
    	
    	if (isset($this->scope)) {
    		$auxString = $auxString."scope=\"".$this->scope."\" ";
    	}
    	
    	if (isset($this->rowSpan)) {
    		$auxString = $auxString."rowspan=\"".$this->rowspan."\" ";
    	}
    	
    	if (isset($this->colSpan)) {
    		$auxString = $auxString."colspan=\"".$this->colSpan."\" ";
    	}
        
        $auxString = $auxString.">\n";
        
        /*
         * Additions of the inner elements of the h1 element to the return 
         * string.
         */
        if (count($this->elements) > 0) {
            foreach ($this->elements as $element) {
                $auxString = $auxString.$element->toString();
            }
        }
        
        return $auxString;
    }
    
}

?>